using System;
using NetMigration.Domains;
using NetMigration.Factories;

namespace NetMigration.Utilities
{
    public abstract class Migration
    {
        protected Migration()
        {
        }

        protected Migration(IMigrationFactory factory)
        {
            MigrationFactory = factory;
        }

        public IMigrationFactory MigrationFactory { get; set; }

        public void CreateTable(string tableName)
        {
            CreateTable(tableName, delegate { });
        }

        public void DropTable(string tableName)
        {
            MigrationFactory.CreateTableInstance(tableName).Drop();
        }

        public void CreateTable(string tableName, Action<ITable> actions)
        {
            var table = MigrationFactory.CreateTableInstance(tableName);
            actions(table);
            table.Create();
        }

        public abstract void Up();
        public abstract void Down();
    }
}